//{=========================================================================
//! @file D6.c
//! @date 05.10.2013 17:57
//! @author Andrey Drobyshev <immortalguardian1@gmail.com>
//! @ version 1.0
//!
//! @par	Conditions:
//! 		The program reads a natural number and prints the number of its
//!         decomposotions of unordered natural summands.
//}=========================================================================

#include <stdio.h>
#include <assert.h>

#define TableSize 101

//{======================================================================
//! Function fill_out - fills out the table with intermediate values.
//!
//! @param           N   -   the number of table's strings.
//! @param[out]      table [][N] - the table itself.
//!
//! @return     nothing
//!
//! @note       The function has assertion checks.
//}======================================================================

void fill_out ( unsigned int N, unsigned int table [][N]);

//{======================================================================
//! Function output - displays sought-for value.
//!
//! @param           N   -   the number of table's strings.
//! @param[out]      table [][N] - the table itself.
//!
//! @return     nothing
//!
//! @note       The function has assertion checks.
//}======================================================================

void output ( unsigned int N, unsigned int table [][N]);

//{=========================================================================
//! Function main - prints welcome messages and the result, initializes
//! the table, manages all the program execution.
//!
//! @return     0 on success
//! @note       The function uses functions "fill_out", "output".
//}==========================================================================

int main ()
{
    printf ( "#Hello!\n"
             "#This program get your natural number "
             "and outputs the number of its\n#decomposotions "
             "of unordered natural summands.\n\n");
    printf ( "#Please enter your number: ");

    unsigned int N = 0;

    scanf ( "%u", &N);

    unsigned int table [TableSize][TableSize] = {};

    fill_out ( N, table);
    output ( N, table);

    return 0;
}

void fill_out ( unsigned int N, unsigned int table [][N])
{
    assert ( table != NULL);

    unsigned int i = 0, j = 0;

    for ( i = 1; i <= N; i++)       // Initializing
    {
        assert ( 0 <= i && i <= N);
        table [i][1] = 1;
    }

    for ( i = 2; i <= N; i++)
    {
        assert ( 1 <= i && i <= N);
        for ( j = 2; j <= i; j++)
        {
            assert ( 1 <= j && j <= N);
            table [i][j] = table [i-1][j-1] + table [i-j][j];
        }
    }

    return;
}

void output ( unsigned int N, unsigned int table [][N])
{
    unsigned int i = 1, s = 0;

    while ( table [N][i])
    {
        s += table [N][i];
        i++;
    }

    printf ( "\nThe number of decompositions is %u.\n", s);

    return;
}
